'use strict';

const Service = require('egg').Service;

class ExamService extends Service {
    /**
     * 考试类型
     */
    async readTypeList() {
        let sql = 'select * from exam_type';
        const res = await this.app.mysql.query(sql);
        return res;
    }

    /**
     * 随机获取试题
     * @param {*} etid
     * @param {*} sid
     * @param {*} num
     */
    async getRandomQuestion(etid, sid, num) {
        // 找出符合条件的题，使用 sql 的 rand 函数随机抽题 num 道题
        let sql = `

        `;
        let params = [etid, sid, num];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }

    /**
     * 添加考试
     */
    async add({ name, etid, sid, num, start, end }) {
        // 获取试题
        const questionList = await this.getRandomQuestion(etid, sid, num);
        // 添加试卷
        let sql = `INSERT INTO exam (id, title, desc, status, num, start_time, end_time, qids, etid, sid, uid) VALUES ()`;
        // 生成试卷id
        const eid = this.ctx.helper.uuid();
        // 问题 ids
        // 插入数据
        let params = [eid, name, '', 1, num, start, end];
    }
}

module.exports = ExamService;
